package site.luojie.framework.paser;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;
import java.util.List;

/**
 * @Description: SqlMapConfig.xml解析类
 * @Author jie.luo
 * @Create: 2020-04-28 11:21
 **/
public class XMLConfigBuilder {


    /**
     * 解析 xml 配置文件
     *
     * @param inputStream 配置文件字节码
     * @return scanPackage
     */
    public String parse(InputStream inputStream) throws DocumentException {

        Document document = new SAXReader().read(inputStream);

        Element rootElement = document.getRootElement();

        List<Element> propertyElements = rootElement.selectNodes("//scan");

        String scanPackage = null;
        for (Element propertyElement : propertyElements) {
            scanPackage = propertyElement.attributeValue("package");
        }

        return scanPackage;
    }

}
